package item;

import inventory.EquipLocation;
import loadsave.Memento;
import loadsave.loadsaveobject.LoadSaveObject;
import loadsave.loadsaveobject.LoadSaveObjectComposite;
import loadsave.loadsaveobject.LoadSavePrimitive;
import stat.StatList;
import stat.NonEntityStatList;

public abstract class EquipableItem extends TakeableItem {
	
	private String activeSkillName;
    private StatList statList;
    private EquipLocation equipLocation;
    
    public EquipableItem() { }
    
    public EquipableItem( String name ) {
        super(name);
        statList = new NonEntityStatList();
        equipLocation = null;
        activeSkillName = null;
    }
    
    public EquipableItem( String name, StatList statList, String activeSkillName ) {
        super(name);
        this.statList = statList;
        this.activeSkillName = activeSkillName;        
    }
    
    /**
     * have the visitor visit this item to pick it up
     */
    public void accept( visitors.TakeableItemVisitor tiv ) {
        tiv.visitEquipableItem(this);
    }

    /**
     * set the enum for the equip location for this item to equip to
     * @param loc
     */
    public void setEquipLocation(EquipLocation loc) {
    	equipLocation = loc;
    }
    
    /**
     * set the value for the active skill, that is the skill
     * needed to equip this
     * @param activeSkillName
     */
    public void setActiveSkillName(String activeSkillName) {
    	this.activeSkillName = activeSkillName;
    }
    
    /**
     * accessor for active skill
     * @return
     */
    public String getActiveSkillName() {
    	return activeSkillName;
    }
    
    /**
     * get enum for the location to equip to
     * @return
     */
    public EquipLocation getEquipLocation() {
    	return equipLocation;
    }
    
    /**
     * memento to save/load this
     */
    @Override
    public Memento getMemento() {
        return new Memento() {

            @Override
            public LoadSaveObject getState() {
                LoadSaveObjectComposite toReturn = new LoadSaveObjectComposite("", "Equippable");
                toReturn.add("activeSkillName", new LoadSavePrimitive("activeSkillName", "String", activeSkillName));
                LoadSaveObject sl = statList.getMemento().getState();
                sl.setName("statList");
                toReturn.add(sl.getName(), sl);
                toReturn.add("equipLocation", new LoadSavePrimitive("equipLocation", "String", String.valueOf(equipLocation)));
                return toReturn;
            }

            @Override
            public void restoreState(LoadSaveObject lso) {
                activeSkillName = lso.get("activeSkillName").getValue();
                statList = new NonEntityStatList();
                statList.getMemento().restoreState(lso.get("statList"));
                equipLocation = EquipLocation.valueOf(lso.get("equipLocation").getValue());
                
            }
            
        };
    }
 
}
